package com.echo.code.spring.core;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Description
 *
 * @author baiyp
 * @version 1.0.0
 * @date 2019/04/14
 */
@Setter
@Getter
@ToString
@Component
public class Car implements ApplicationContextAware {

  @Value("${car.name}")
  private String name;

  @Value("${car.price}")
  private double price;

  @Value("${car.info}")
  private String info;

  private ApplicationContext context;

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.context = applicationContext;
  }

  public void describe() {
    Car car = context.getBean(Car.class);
    car.describe(this);
  }

  public void describe(Car car) {
    System.out.println("this is car: " + this.toString());
  }
}
